package com.shsubway.activity.com;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.widget.Button;

import com.rengwuxian.materialedittext.MaterialEditText;
import com.shsubway.R;
import com.shsubway.base.BaseActivity;
import com.shsubway.model.BackEntity;
import com.shsubway.model.StaffEntity;
import com.shsubway.utils.Constant;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class BackActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.my_back)
    MaterialEditText myBack;
    @BindView(R.id.btn_comit)
    Button btnComit;
    Intent intent;
    Bundle bundle;
    StaffEntity staffEntity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_back);
        ButterKnife.bind(this);
        initView();

    }

    private void initView() {
        setTitleBar(toolbar,"意见反馈");
        toolbar.setNavigationOnClickListener(v -> finish());
        intent = getIntent();
        bundle = intent.getExtras();
        staffEntity = (StaffEntity) bundle.getSerializable(Constant.STAFFENTITY);
    }

    @OnClick(R.id.btn_comit)
    public void onClick() {
        if (TextUtils.isEmpty(myBack.getText().toString().trim())) {
            toast("输入内容不能为空");
        } else {
            BackEntity backEntity = new BackEntity();
            backEntity.setUserId(staffEntity.getStaff_phone());
            backEntity.setBackContent(myBack.getText().toString().trim());
            backEntity.save(new SaveListener<String>() {
                @Override
                public void done(String s, BmobException e) {
                    if (e == null) {
                        toast("提交成功，万分感谢您的反馈。");
                        finish();
                    } else {
                        toast("提交失败，请稍后重试");
                    }
                }
            });
        }
    }
}
